﻿using System;
using System.Collections;
using System.Web;
using System.Web.Caching;
using Framework.Library.Core.Config;
using Framework.Library.Core.Provider.Caches;
using System.Collections.Generic;

namespace Framework.Library.Core.Provider.Caches
{
    public class Caching
    {
        private static Caching data = new Caching();
        public static Caching Data
        {
            get { return data; }
        }

        public T Get<T>(string key, string parameters = null)
        {
            return Instance.Get<T>(key, parameters);
        }
        public List<string> GetAll()
        {
            return Instance.GetAll();
        }
        public void Set<T>(string key, T data, string parameters = null)
        {
            Instance.Set<T>(key, data, parameters);
        }
        public void Set<T>(string key, T data, int cacheTime, string parameters = null)
        {
            Instance.Set<T>(key, data, cacheTime, parameters);
        }
        public void Invalidate()
        {
            Instance.Invalidate();
        }
        public void Invalidate(string key, string parameters = null)
        {
            Instance.Invalidate(key, parameters);
        }
        public void InvalidateRegion(string key)
        {
            Instance.InvalidateRegion(key);
        }

        private ICaching Instance
        {
            get
            {
                ICaching caching;
                switch (Configurations.CacheName)
                {
                    case "MEMORYCACHE":
                        caching = new CacheMemory();
                        break;
                    case "HTTPCACHE":
                        caching = new CacheMemory();
                        break;
                    case "ENTERPRISECACHE":
                        caching = new CacheMemory();
                        break;
                    case "DEPENDENCYCACHE":
                        caching = new CacheMemory();
                        break;
                    default:
                        caching = new CacheMemory();
                        break;
                }
                return caching;
            }
        }
    }
    
}